package net.aiion.weave.impl.bytecode.events;

import net.aiion.weave.asm.Attribute;
import net.aiion.weave.spi.bytecode.BytecodeClassVisitor;
import net.aiion.weave.spi.bytecode.BytecodeFieldVisitor;
import net.aiion.weave.spi.bytecode.BytecodeMethodVisitor;
import net.aiion.weave.spi.bytecode.BytecodeVisitor;
import net.aiion.weave.spi.bytecode.events.AttributeBytecodeEvent;

public class AttributeBytecodeEventImpl extends BytecodeEventImpl implements AttributeBytecodeEvent
{
    private Attribute attribute;

    public AttributeBytecodeEventImpl(final Attribute aAttribute) {
        attribute = aAttribute;
    }

    @Override
    public int getType() {
        return ATTRIBUTE;
    }

    @Override
    public void setAttribute(final Attribute aAttribute) {
        attribute = aAttribute;
    }

    @Override
    public Attribute getAttribute() {
        return attribute;
    }

    @Override
    public BytecodeVisitor acceptBytecodeVisitor(final BytecodeVisitor aBytecodeVisitor) {
        final BytecodeClassVisitor bytecodeClassVisitor = aBytecodeVisitor.asBytecodeClassVisitor();
        if (bytecodeClassVisitor != null) {
            bytecodeClassVisitor.visitAttribute(this);
            return aBytecodeVisitor;
        }

        final BytecodeFieldVisitor bytecodeFieldVisitor = aBytecodeVisitor.asBytecodeFieldVisitor();
        if (bytecodeFieldVisitor != null) {
            bytecodeFieldVisitor.visitAttribute(this);
            return aBytecodeVisitor;
        }

        final BytecodeMethodVisitor bytecodeMethodVisitor = aBytecodeVisitor.asBytecodeMethodVisitor();
        if (bytecodeMethodVisitor != null) {
            bytecodeMethodVisitor.visitAttribute(this);
            return aBytecodeVisitor;
        }

        return aBytecodeVisitor;
    }
}
